<?php
if($this->session->userdata('username') != null){
	if($this->session->userdata('role') == 0){
include 'include/header.php';
?>
<h3>Daftar User</h3>
<table class="table">
	<tr>
		<th>No.</th>
		<th>Nama</th>
		<th>Email</th>
		<th>Status</th>
		<th>Aksi</th>
	</tr>
<?php
$a = 1;
foreach($list_user as $user)
{
?>
	<tr>
		<td><?php echo $a++; ?></td>
		<td><?php echo $user['nama']; ?></td>
		<td><?php echo $user['email']; ?></td>
		<td><?php echo ($user['status'] == 1)? "Aktif" : "Tidak Aktif" ?></td>
		<td><?php if($user['status'] == 0){ ?><a href="<?php echo base_url('index.php/admin/list_user/aktifkan/'.$user['id_user']);?>"><button>Aktifkan</button></a><?php } else{ ?><a href="<?php echo base_url('index.php/admin/list_user/nonaktifkan/'.$user['id_user']);?>"><button>Nonaktifkan</button></a><?php } ?></td>
	</tr>
<?php
}
?>
</table>
<?php
include 'include/footer.php';
} else{ 
		echo 'Anda belum login sebagai admin, silahkan login terlebih dahulu dengan klik link berikut';
		echo '<a href="'.base_url('index.php/guest').'">Kembali</a>';
	}
} else
	{
		echo 'Anda belum login sebagai admin, silahkan login terlebih dahulu dengan klik link berikut';
		echo '<a href="'.base_url('index.php/guest').'">Kembali</a>';
	}
	
?>
<script>
function aktifkan(id)
{
	$.post('<?php echo base_url(); ?>index.php/admin/list_user/aktifkan/'+id, {
        });
	window.location.reload(true);
}

function nonaktifkan(id)
{
	$.post('<?php echo base_url(); ?>index.php/admin/list_user/nonaktifkan/'+id, {
        });
	window.location.reload(true);
}
</script>